﻿<div class="container">
    <h3 class="title wow fadeInUp">从 SANANBIO 获取更多信息</h3>
    <form id="subForm" class="wow fadeInUp" data-wow-delay="0.5s" action="/subscribe" method="post">
        <div class="row no-gutters">
            <div class="col">
                <input type="email" id="email" name="email" placeholder="输入您的邮箱地址">
            </div>
            <div class="col-auto">
                <button type="button" id="btnSub"> <i class="iconfont iconright2"></i></button>
            </div>
        </div>
    </form>
</div>
@*<link href="~/layui/css/layui.css" rel="stylesheet" />*@
<script src="~/layui/layui.js"></script>
<script src="~/js/jquery-1.10.2.min.js"></script>
<script>
    layui.use(['layer'], function () {
        var $ = layui.$;
        layer = layui.layer;

        $("#btnSub").click(function () {
            var email = $("#email").val();
            // 正则验证格式
            var reg = /^([a-zA-Z0-9_\.\-])+\@@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            if (!reg.test(email)) {
                layer.msg("请输入有效的邮箱！", { icon: 0, time: 1500 });
                return;
            }
            $.post('/subscribe', { email: email }, function (res) {
                if (res.success) {
                    $("#email").val("");
                    layer.msg("订阅成功！", { icon: 1, time: 1500 });
                }
                else {
                    layer.msg("订阅失败！", { icon: 1, time: 1500 });
                }
            });
        });
    });
</script>
